package com.jml;

import java.util.concurrent.*;

public class CallableTest {

    public static void main(String[] args) throws Exception {
        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
        Future<String> submit = newCachedThreadPool.submit(new TaskCallable());
        String result = submit.get();

        System.out.println(result);
        System.out.println("main end...");
        newCachedThreadPool.shutdown();
       /* //也可以直接调用call方法获取返回值
        String call = new TaskCallable().call();
        System.out.println(call);*/


    }

    static class TaskCallable implements Callable<String>{
        @Override
        public String call() throws Exception {
            System.out.println("running wait 5s  begging");
            Thread.sleep(5000);
            System.out.println("running wait 5s  ending");
            return "I am return result";
        }
    }
}
